<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      
    </div>

    <script src="../js/vue.js"></script>

    <script>
      const app = Vue.createApp({
        data() {
          return {
            cItem: "lk-btn"
          }
        },
        methods:{
          change(){
            this.cItem = this.cItem == 'lk-btn' ? 'lk-input' : 'lk-btn';
          }
        },
        template:`
          <div>
            <keep-alive>
              <component :is="cItem"></component>
            </keep-alive>
            <hr/>
            <button @click="change">切换显示</button>
          </div>
        `
      });
      app.component('lk-btn',{
        template:`<button>itlike.com</button>`
      });
      app.component('lk-input',{
        template:`<input type="text">`
      });
      app.mount('#app');
    </script>
  </body>
</html>